import * as React from 'react';
import {
  Component,
  PropsType
} from 'react';
export default class LogOut extends Component {
  static contextTypes = {
    router: React.PropTypes.any
  };

  state = {
    waiting: 5,
  };

  timer = null;
  componentDidMount() {
    const router = this.context.router;
    this.timer = setInterval(() => {
      if (!this.state.waiting) {
        router.push('/login');
        return;
      }

      this.setState({
        waiting: this.state.waiting-1
      })
    }, 1000);
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }

  render() {
    return (
      <div className="container w-auto-xs">
        <div className="text-center m-b-lg">
          <h1 className="h1 m-t-lg">志多星</h1>
        </div>
        <div className="w-xxl" style={{margin: 'auto'}}>
          <div className="alert alert-success">
            您已退出 系统, 欢迎下次光临! {this.state.waiting} 秒后即将<a href="/">回到首页</a>。
          </div>
        </div>
      </div>
    );
  }
}
